document.addEventListener('DOMContentLoaded', function() {
  const saveButton = document.getElementById('saveButton');
  const messageDiv = document.getElementById('message');

  saveButton.addEventListener('click', function() {
    const domain = document.getElementById('domain').value;
    const groupName = document.getElementById('groupName').value;
    const color = document.getElementById('color').value;

    if (domain && groupName) {
      chrome.storage.sync.get('tabGroups', function(data) {
        const tabGroups = data.tabGroups || [];
        tabGroups.push({ domain, groupName, color });
        chrome.storage.sync.set({ tabGroups }, function() {
          messageDiv.textContent = '保存成功';
          setTimeout(() => {
            window.close();
          }, 1000);
        });
      });
    } else {
      messageDiv.textContent = '请填写所有字段';
    }
  });
});